package com.ruoyi.web.controller.publish;

import java.util.List;

import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.publish.domain.TaskApproval;
import com.ruoyi.publish.service.ITaskApprovalService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【鉴定报告审核】Controller
 *
 * @author confusefox
 * @date 2020-12-30
 */
@Controller
@RequestMapping("/publish/approval")
public class TaskApprovalController extends BaseController {
    private String prefix = "publish/approval";

    @Autowired
    private ITaskApprovalService taskApprovalService;

    @RequiresPermissions("publish:approval:view")
    @GetMapping()
    public String approval() {
        return prefix + "/approval";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("publish:approval:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TaskApproval taskApproval) {
        startPage();
        List<TaskApproval> list = taskApprovalService.selectTaskApprovalList(taskApproval);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("publish:approval:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TaskApproval taskApproval) {
        List<TaskApproval> list = taskApprovalService.selectTaskApprovalList(taskApproval);
        ExcelUtil<TaskApproval> util = new ExcelUtil<TaskApproval>(TaskApproval.class);
        return util.exportExcel(list, "approval");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("publish:approval:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TaskApproval taskApproval) {
        return toAjax(taskApprovalService.insertTaskApproval(taskApproval));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        TaskApproval taskApproval = taskApprovalService.selectTaskApprovalById(id);
        mmap.put("taskApproval", taskApproval);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("publish:approval:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TaskApproval taskApproval) {
        return toAjax(taskApprovalService.updateTaskApproval(taskApproval));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("publish:approval:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(taskApprovalService.deleteTaskApprovalByIds(ids));
    }

    /**
     * 添加或者更新审批人信息
     */
    @Log(title = "【添加或者更新审批人信息】", businessType = BusinessType.INSERT)
    @PostMapping("/addOrUpdateTask")
    @ResponseBody
    public AjaxResult addOrUpdateTask(TaskApproval taskApproval) {
        return toAjax(taskApprovalService.addOrUpdateTask(ShiroUtils.getSysUser().getUserId(),taskApproval));
    }

    @Log(title = "【鉴定报告审批】", businessType = BusinessType.INSERT)
    @PostMapping("/handleTaskApproval")
    @ResponseBody
    public AjaxResult handleTaskApproval(TaskApproval taskApproval) {
        return toAjax(taskApprovalService.handleTaskApproval(ShiroUtils.getSysUser().getUserId().toString(), ShiroUtils.getSysUser().getUserName(), taskApproval));
    }
}
